package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import Entity.DisabledReport;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/***
 * this is the GUI for viewing the disabled parking spot report by the company manager.
 * @author Shahar Shelly
 */
public class ViewDisabledReport extends JFrame {

	private JPanel contentPane;
	private JTextField startDate;
	private JTextField endDate;
	private JTextField ComplaintNum;
	private JTextField Depth;
	private JTextField Height;
	private JTextField Column;
	private JTable table;
	private JTextField textField;
	
	
	JFrame frame;
	JPanel lastPanel;
	public void setLastPanel (JPanel panel)
	{
		this.lastPanel=panel;
	}
	
	public void setFrame (JFrame frame)
	{
		this.frame=frame;
	}

	/**
	 * is the constructor. it has a table to chose from and save after validate.
	 */
	public ViewDisabledReport(DisabledReport d) 
	{
		final DisabledReport c2=d;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 760, 326);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.setLayout(null);
		
		final JLabel lblDisabledReport = new JLabel("Disabled Places Report ");
		lblDisabledReport.setBounds(175, 11, 161, 14);
		contentPane.add(lblDisabledReport);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 33, 98, 43);
		panel.setBorder(new TitledBorder(null, "Start Date", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel);
		panel.setLayout(null);
		
		startDate = new JTextField();
		startDate.setBounds(6, 16, 86, 20);
		panel.add(startDate);
		startDate.setColumns(10);
		startDate.setText(d.getStart().getDate()+"/"+(d.getStart().getMonth()+1)+"/"+(d.getStart().getYear()+1900));
		startDate.setEditable(false);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(10, 77, 98, 43);
		panel_1.setBorder(new TitledBorder(null, "End Date", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		endDate = new JTextField();
		endDate.setBounds(6, 16, 86, 20);
		panel_1.add(endDate);
		endDate.setColumns(10);
		endDate.setText(d.getEndDate().getDate()+"/"+(d.getEndDate().getMonth()+1)+"/"+(d.getEndDate().getYear()+1900));
		endDate.setEditable(false);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBounds(10, 131, 180, 108);
		panel_2.setBorder(new TitledBorder(null, "Description", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		final JTextPane textPane = new JTextPane();
		textPane.setBounds(6, 16, 164, 81);
		panel_2.add(textPane);
		
		JLabel lblNumberOfComplaints = new JLabel("Number of Disabled Spaces:");
		lblNumberOfComplaints.setBounds(252, 255, 151, 14);
		contentPane.add(lblNumberOfComplaints);
		
		ComplaintNum = new JTextField();
		ComplaintNum.setBounds(413, 252, 40, 20);
		contentPane.add(ComplaintNum);
		ComplaintNum.setColumns(10);
		ComplaintNum.setText(String.valueOf(d.getDisabledNumber()));
		ComplaintNum.setEditable(false);
		
		JLabel lblDepth = new JLabel("Depth:");
		lblDepth.setBounds(572, 33, 81, 14);
		contentPane.add(lblDepth);
		
		Depth = new JTextField();
		Depth.setBounds(617, 30, 86, 20);
		contentPane.add(Depth);
		Depth.setColumns(10);
		Depth.setEditable(false);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "Reason:", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel_3.setBounds(572, 117, 168, 92);
		contentPane.add(panel_3);
		panel_3.setLayout(null);
		
		final JTextPane textPane_1 = new JTextPane();
		textPane_1.setBounds(6, 16, 150, 69);
		panel_3.add(textPane_1);
		
		JLabel label = new JLabel("Height:");
		label.setBounds(572, 59, 81, 14);
		contentPane.add(label);
		
		Height = new JTextField();
		Height.setColumns(10);
		Height.setBounds(617, 56, 86, 20);
		contentPane.add(Height);
		Height.setEditable(false);
		
		JLabel label_1 = new JLabel("Column:");
		label_1.setBounds(572, 89, 81, 14);
		contentPane.add(label_1);
		
		Column = new JTextField();
		Column.setColumns(10);
		Column.setBounds(617, 86, 86, 20);
		contentPane.add(Column);
		Column.setEditable(false);
		
		table = new JTable(new MyDisabled(d.getDisable()));
		table.setBounds(270, 64, 241, 124);
		JScrollPane sp=new JScrollPane(table);
		sp.setBounds(200, 36, 352, 203);
		contentPane.add(sp);
		
		JLabel lblParkingLot = new JLabel("Parking Lot:");
		lblParkingLot.setBounds(357, 11, 81, 14);
		contentPane.add(lblParkingLot);
		
		textField = new JTextField();
		textField.setBounds(435, 8, 29, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		textField.setEditable(false);
		
		JButton btnReturn = new JButton("Return");
		btnReturn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				close();
				frame.setContentPane(lastPanel);
				frame.setVisible(true);
			}
		});
		btnReturn.setBounds(10, 250, 89, 23);
		contentPane.add(btnReturn);
		
		table.addMouseListener(new MouseAdapter() {
			  public void mouseClicked(MouseEvent e) {
			    if (e.getClickCount() == 2) {
			      JTable target = (JTable)e.getSource();
			      int row = target.getSelectedRow();
			      Depth.setText(String.valueOf(c2.getDisable()[row].getPlace()[0]));
			      Column.setText(String.valueOf(c2.getDisable()[row].getPlace()[1]));
			      Height.setText(String.valueOf(c2.getDisable()[row].getPlace()[2]));
			      textPane.setText(c2.getDisable()[row].getDescription());
			    }
			  }
		});
	}
	public void close()
	{
		WindowEvent windowclose=new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
		Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(windowclose);
	}
}
